﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using DevExpress.Xpf.Core;
using ThanNhanTao.Server;
using ThanNhanTao.Server.BLL;
using ThanNhanTao.Server.Enum;
using ThanNhanTao.Server.Entities;


namespace ThanNhanTao
{
    /// <summary>
    /// Interaction logic for frmThongKeTongBNChayThan.xaml
    /// </summary>
    public partial class frmThongKeTongBNDungThuoc : DXWindow
    {
        Dm_YeuCauBLL yeuCauBLL;
        PhieuBenhNhanBll phieuBenhNhanBll;
        public frmThongKeTongBNDungThuoc()
        {
            InitializeComponent();
            yeuCauBLL = new Dm_YeuCauBLL();
            phieuBenhNhanBll = new PhieuBenhNhanBll();
            cboKhuVuc.SelectedIndex = 0;
            List<Dm_YeuCau> listYeuCau = yeuCauBLL.RertieveAllDichTruyenThuocNoiTru();
            //listYeuCau.Insert(0,new Dm_YeuCau{MaYeuCau = "", TenYeuCau=" -- Tất cả --"});
            cboTenThuoc.ItemsSource = listYeuCau;
            cboTenThuoc.SelectedIndex = 0;
        }

        private void btnDong_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void btnThongKe_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                int trangThaiBenhNhan = EnumTrangThaiBenhNhan.TatCa;
                //if(rdoDangDieuTri.IsChecked == true)
                //    trangThaiBenhNhan = EnumTrangThaiBenhNhan.DangDieuTri;
                //else if(rdoRaVien.IsChecked == true)
                //    trangThaiBenhNhan = EnumTrangThaiBenhNhan.RaVien;
                Dm_YeuCau dmYeuCau = cboTenThuoc.EditValue as Dm_YeuCau;
                List<BenhNhanEntities> listBenhNhan = phieuBenhNhanBll.ThongKeBNDungThuoc(calendar.StartDate, calendar.EndDate
                                                    , cboKhuVuc.SelectedIndex == 0 ? string.Empty : cboKhuVuc.DisplayText
                                                    , dmYeuCau != null ? dmYeuCau.MaYeuCau : string.Empty, trangThaiBenhNhan);
                GridDanhSachBenhNhan.ItemsSource = listBenhNhan;
                GridDanhSachBenhNhan.RefreshData();
            }
            catch (Exception)
            {
                DXMessageBox.Show("Thống kê không thành công", "Thông báo", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
    }
}
